import 'package:flutter/material.dart';
import 'package:flutter_chapter_05/src/dialogs/dialog/MyToast.dart';
import 'package:flutter_chapter_05/src/dialogs/dialog/dialog.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: Scaffold(
        appBar: AppBar(title: const Text("Flutter App")),
        body: const LayoutDemo(),
      ),
    );
  }
}



class LayoutDemo extends StatelessWidget {
  const LayoutDemo({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Center(
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: <Widget>[
          ElevatedButton(
            onPressed: () async{
              var result = await showDialog(context: context,
                  builder: (context){
                  return AlertDialog(
                    title: const Text("title..."),
                    content: const Text("这里是内容"),
                    actions: [
                      TextButton(
                          onPressed: () {
                            print("ok");
                            Navigator.of(context).pop("ok"); //点击按钮让AlertDialog消失
                          },
                          child: const Text("确定")),
                      TextButton(
                          onPressed: () {
                            print("cancel");
                            Navigator.of(context).pop("取消");
                          },
                          child: const Text("取消"))
                    ],
                  );
              }
              );

              print("result:$result");

            },
            child: const Text('alert弹出框-AlertDialog '),
          ),
          const SizedBox(height: 20),
          ElevatedButton(
            onPressed: () async{
                var result = await showDialog(context: context, builder: (context){
                  return SimpleDialog(
                    title: const Text("这里是title"),
                    children: [
                      SimpleDialogOption(
                        onPressed: () {
                          print("汉语");
                          Navigator.pop(context, "汉语");
                        },
                        child: const Text("汉语"),
                      ),
                      const Divider(),
                      SimpleDialogOption(
                        onPressed: () {
                          print("英语");
                          Navigator.pop(context, "英语");
                        },
                        child: const Text("英语"),
                      ),
                      const Divider(),
                      SimpleDialogOption(
                        onPressed: () {
                          print("日语");
                          Navigator.pop(context, "日语");
                        },
                        child: const Text("日语"),
                      ),
                      const Divider(),
                    ],
                  );
                });

                print("result:$result");

            },
            child: const Text('select弹出框-SimpleDialog'),
          ),
          const SizedBox(height: 20),
          ElevatedButton(
            onPressed: () async{
              showDialog(context: context, builder: (context){
                return MyDialog(title: "title....", onClosed: (){

                });
              });
            },
            child: const Text('自定义dialog'),
          ),
          const SizedBox(height: 20),
          ElevatedButton(
            onPressed: () async{
              showModalBottomSheet(
                  context: context,
                  builder: (context){
                    return SizedBox(
                      height: 240,
                      child: Column(
                        crossAxisAlignment: CrossAxisAlignment.center,
                        children: [
                          ListTile(
                            title: const Text("分享"),
                            onTap: () {
                              print("分享");
                              Navigator.of(context).pop("分享");
                            },
                          ),
                          const Divider(),
                          ListTile(
                            title: const Text("收藏"),
                            onTap: () {
                              print("收藏");
                              Navigator.of(context).pop("收藏");
                            },
                          ),
                          const Divider(),
                          ListTile(
                            title: const Text("取消"),
                            onTap: () {
                              print("取消");
                              Navigator.of(context).pop("取消");
                            },
                          ),
                          const Divider(),
                        ],
                      ),
                    );
                  }
              );
            },
            child: const Text('ActionSheet底部弹出框'),
          ),
          const SizedBox(height: 20),
          ElevatedButton(
            onPressed: (){
              // Fluttertoast.showToast(
              //     msg: "提示信息",
              //     toastLength: Toast.LENGTH_LONG,   //值针对 android 平台
              //     gravity: ToastGravity.CENTER, //方位
              //     timeInSecForIosWeb: 1,  //提示时间 针对ios 和 web
              //     backgroundColor: Colors.black38, //背景颜色
              //     textColor: Colors.white,   //文本颜色
              //     fontSize: 13.0  //文本字体大小
              // );

              // //自己去制作一个图层独立的组件（图层）
              // OverlayEntry entry = OverlayEntry(
              //     builder: (BuildContext context) {
              //
              //       return Positioned(
              //           child: const Text("data");
              //       );
              //
              //     }
              // );
              //
              // //插入一个图层在顶层
              // //insert 组件树
              // Overlay.of(context)?.insert(entry);
              //
              // Future.delayed(Duration(milliseconds: 2000)).then((value) => entry.remove());



              Toast.showInfo("这个是消息", context: context);



            },
            child: const Text('Toast'),
          ),
          // fluttertoast
        ],
      ),
    );
  }
}

